home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 27.zip / BS1 part 27 / ImageMaster_d3.adf / piarc.lzh.parta / MetaScanIM.rexx < prev    next >
OS/2 REXX Batch file  |  1993-03-23  |  8KB  |  353 lines

  1. /*
  2.  
  3.  $Id: MetaScanIM.rexx,v 1.4 1993/01/16 00:04:13 Vic Exp $
  4.  
  5.  $Log: MetaScanIM.rexx,v $
  6.  * Revision 1.4  1993/01/16  00:04:13  Vic
  7.  * Added   - an 'options failat...' to keep the script from complaining if
  8.  *           it's terminated by closing MetaScanIM
  9.  *         - a port of our own ('MetaScanRexxing') so we can make sure we
  10.  *           don't accidently get re-executed.  If we ARE re-executed, we
  11.  *           simply bring MetaScanIM 'tofront' and exit gracefully
  12.  *         - an OPTIONS RESULTS at the beginning of the loop (I'm not sure
  13.  *           how it gets left at the end of the loop).
  14.  *         - some calls to 'closeport' to close our port
  15.  * Changed - the location of where we initialize MetaScanPort
  16.  * Delete  - the automatic "Preview" when MetaScanIM is 1st loaded
  17.  *
  18.  * Revision 1.3  1993/01/15  22:50:14  Vic
  19.  * Added   - an ADDRESS(MetaScanPort) in the 'do forever' loop so WE get
  20.  *           the 'getscan' command instead of Imagemaster
  21.  *
  22.  * Revision 1.2  1993/01/14  21:59:30  Vic
  23.  * Changed - some spellings to add the 'IM' to the end of some 'MetaScan's
  24.  *
  25.  * Revision 1.1  1993/01/13  21:49:32  Vic
  26.  * Initial revision
  27.  *
  28. Revision 1.3  92/04/13  15:02:58  Vic
  29. Added   - stuff to let us supply unique name for scanned buffers
  30. Changed - 'newbuf' to 'newasprimary' so the added code works
  31.  
  32. Revision 1.2  92/01/10  02:19:44  Ken
  33. Changed - The loading of metascan to look in the current directory
  34.           or the current path and not just c:.
  35.  
  36.           Changed the name of scanner to metascan.
  37.  
  38. Revision 1.1  91/12/30  23:04:41  Ken
  39. Initial revision
  40.  
  41.  
  42.  *
  43.  * MetaScan.rexx
  44.  *
  45.  *  Written by: Kenneth T. Spoor
  46.  * Last Update: 21 Dec 1991
  47.  *    Revision: 1.1
  48.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  49.  *
  50.  * Note: This script is created by modifying one of Black Belt Systems
  51.  *       existing scripts.  Thanks Ben!
  52.  */
  53.  
  54. options failat 600
  55. call pragma('stack',20000);
  56.  
  57. /*
  58.  * open rexxsupport.library -- needed for some functions
  59.  */
  60. IF ~SHOW('L',"rexxsupport.library") THEN
  61.   DO
  62.     IF ADDLIB('rexxsupport.library',0,-30,0) THEN
  63.       DO
  64.         /* everything's ok */
  65.       END;
  66.     ELSE
  67.       DO
  68.         SAY 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  69.         SAY 'Cannot operate MetaScanIM.rexx without this library - sorry!';
  70.         EXIT(10);
  71.       END;
  72.   END;
  73.  
  74. /*
  75.  *  If the script is running already, just 'push' the MetaScanIM screen
  76.  *  to the front.  To the user, it should be indistinguishable from just
  77.  *  starting the script.
  78.  */
  79.  
  80. MetaScanPort = 'METASCAN';
  81. IF SHOW('P','MetaScanRexxing') THEN
  82.   DO
  83.     ADDRESS(MetaScanPort);
  84.     ToFront; /* Bring MetaScan Screen forward */
  85.     ToFront; /* Bring MetaScan Screen forward */
  86.  
  87.     EXIT(0);
  88.   END;
  89. call openport('MetaScanRexxing');
  90.  
  91. /*
  92.  * This will automatically direct the script to the proper
  93.  * software, If it is running. No matter where the script is
  94.  * launched from. :^) I sure do like ARexx. :^))
  95.  */
  96.  
  97. IM_PortName = 'IM_Port'; /* assume Image Professional */
  98.  
  99. IF SHOW('P',IM_PortName) = 0 THEN
  100.   DO
  101.     SAY "Can't find Imagemaster's ARexx port!!!"; /* not running? */
  102.     SAY "This script requires Imagemaster to run!";
  103.     call closeport('MetaScanRexxing');
  104.     EXIT(20);
  105.   END;
  106.  
  107. /*
  108.  * We Only Load From The Scanner
  109.  */
  110.  
  111. ADDRESS(IM_PortName);
  112. OPTIONS RESULTS;
  113.  
  114. /*
  115.  * PI driver for MetaScanIM
  116.  */
  117.  
  118.   OpenedMetaScan = 0;
  119.  
  120.   IF SHOW('P', MetaScanPort) = 0 THEN
  121.     DO
  122.       ADDRESS COMMAND 'run cmpi:MetaScanIM behind';
  123.       count = 0;
  124.  
  125.       ADDRESS COMMAND WaitForPort MetaScanPort;
  126.  
  127.       IF RC ~= 0 THEN
  128.         DO
  129.           SAY "Can't find MetaScanIM!!!";
  130.           SAY "This script requires MetaScanIM to be running or";
  131.           SAY " the program to be in the CMPI: assignment!";
  132.           CALL DoExit(30);
  133.         END;
  134.  
  135.       ADDRESS(MetaScanPort);
  136.       OPTIONS RESULTS;
  137.  
  138.       count = 0;
  139.  
  140.       DO WHILE count < 20
  141.         ScannerReady;
  142.         IF RESULT = "READY" THEN BREAK
  143.         ELSE ADDRESS COMMAND "wait 1";
  144.         count = count + 1;
  145.       END;
  146.  
  147.       ScannerReady;
  148.  
  149.       IF RESULT ~= "READY" THEN
  150.         DO
  151.           SAY "Error - MetaScanIM didn't become ready!!!";
  152.           CALL DoExit(40);
  153.         END
  154.  
  155.       OpenedMetaScan = 1;
  156.     END
  157.  
  158. /*
  159.  * At this point, we have at least some assurance that we
  160.  * have 'MetaScanIM' running.  Now, we need to let the user
  161.  * select the image they wants, so we can open a new
  162.  * buffer of the appropriate size.
  163.  */
  164.  
  165.   ADDRESS(MetaScanPort);
  166.  
  167.   ToFront; /* Bring MetaScan Screen forward */
  168.   ToFront; /* Bring MetaScan Screen forward */
  169.  
  170.   OPTIONS RESULTS;
  171.  
  172.   'SetViewMode None';
  173.  
  174.   DO FOREVER
  175.     OPTIONS RESULTS;
  176.     ADDRESS(MetaScanPort);
  177.     GetScan;
  178.  
  179.     IF RC ~= 0 THEN
  180.       DO
  181.         ADDRESS COMMAND "wait 1";
  182.         CALL DoExit(50);
  183.       END;
  184.  
  185.     Current; /* get the image imformation */
  186.  
  187.     Settings = RESULT;
  188.  
  189.     OPTIONS;
  190.  
  191.     PARSE VAR Settings ScanMode Measure Start_X Start_Y Width Height
  192.  
  193.   /*
  194.     XDPI
  195.     YDPI
  196.     XZoom
  197.     YZoom
  198.     Planes
  199.     DropoutColor
  200.     Halftoning
  201.     GammaCorrection
  202.     ColorCorrection
  203.     Brightness
  204.     Keep
  205.   */
  206.  
  207.     ADDRESS(IM_PortName);
  208.  
  209.     'imtofront'; /* show user the IM screen */
  210.  
  211.     /* is there already a primary buffer??? */
  212.     OPTIONS RESULTS;
  213.  
  214.     'current';
  215.     bufdata = RESULT;
  216.  
  217.     OPTIONS;
  218.  
  219.     PARSE VAR bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  220.  
  221.     IF bname ~= '<none>' THEN
  222.       DO
  223.         ADDRESS(IM_PortName);
  224.         OPTIONS RESULTS;
  225.  
  226.         'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  227.         prefs = RESULT;
  228.  
  229.         OPTIONS;
  230.         ADDRESS;
  231.  
  232.         IF prefs = 0 THEN
  233.           DO
  234.             ADDRESS(IM_PortName);
  235.             'killbuff '||bnum; /* this kills the Primary Buffer */
  236.             ADDRESS;
  237.           END;
  238.       END;
  239.  
  240.   ADDRESS(MetaScanPort);
  241.  
  242.   ToFront; /* Bring MetaScan Screen forward */
  243.   ToFront; /* Bring MetaScan Screen forward */
  244.  
  245.     /* New buffer is created at current resolution */
  246.     ADDRESS(IM_PortName);
  247.  
  248.     'autoredraw 0';
  249.     'newasprimary '||Width||' '||Height;
  250.  
  251.     OPTIONS RESULTS;
  252.  
  253.     'current';
  254.     bufdata = RESULT;
  255.  
  256.     OPTIONS;
  257.  
  258.     PARSE VAR bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  259.  
  260.     OPTIONS RESULTS;
  261.  
  262.     'buffers';
  263.     s = RESULT;
  264.  
  265.     idx = 0;
  266.  
  267.     f = "MetaScan";
  268.     do i = 1 while length(subword(s,i,1)) > 0
  269.       p = subword(s,i, 1)           /* isolate the current suspect */
  270.       if (pos(upper(f), upper(p))) ~= 1 then iterate  /* something irrelevant? */
  271.       if pos(",", p) = 0 then iterate  /* ignore things I dont understant */
  272.       p = substr(p, length(f)+1)    /* get the stuff behind our name */
  273.       if (p = ',') then
  274.         idxt = 1                    /* nothing behind so nominate 1 */
  275.       else
  276.         idxt = substr(p,1,length(p)-1)+1   /* nominate one past this one */
  277.       if idx < idxt then            /* will our nomination pass?? */
  278.         idx = idxt
  279.     end
  280.  
  281.     if idx == 0 then
  282.      do
  283.       'rename '||bnum||'  MetaScan';
  284.      end
  285.     else
  286.      do
  287.       'rename '||bnum||'  MetaScan'||idx;
  288.      end
  289.  
  290.     'autoredraw 1';
  291.  
  292.     ADDRESS(IM_PortName);
  293.     OPTIONS RESULTS;
  294.  
  295.     jackin;
  296.     jackadr = RESULT;
  297.  
  298.  
  299.   ADDRESS(MetaScanPort);
  300.  
  301.     OPTIONS RESULTS;
  302.     Status = 0;
  303.  
  304.     IMGetImage jackadr;  /* copy the scan to IM */
  305.  
  306.     IF RC ~= 0 THEN Status = 60;
  307.  
  308.     CALL DoExit(Status);
  309.   END;
  310.  
  311. DoExit:
  312.   ARG RetCode;
  313.  
  314.   ADDRESS(IM_PortName);
  315.  
  316.   'imtofront';
  317.  
  318.   IF SHOW('P', MetaScanPort) ~= 0 THEN
  319.     DO
  320.       IF OpenedMetaScan = 1 THEN
  321.         DO
  322.           OPTIONS RESULTS;
  323.  
  324.           'askyn '||'"Keep MetaScanIM Loaded" "Remove MetaScanIM"'
  325.           prefs = RESULT;
  326.  
  327.           OPTIONS;
  328.  
  329.           IF prefs ~= 0 THEN
  330.             DO
  331.               ADDRESS(MetaScanPort);
  332.  
  333.               Quit;   /* get rid of MetaScanIM */
  334.  
  335.               ADDRESS;
  336.               OPTIONS;
  337.               call closeport('MetaScanRexxing');
  338.               EXIT(RetCode);
  339.             END;
  340.         END;
  341.     END;
  342.  
  343.   IF RetCode = 0 THEN
  344.     DO
  345.       'redraw';
  346.       RETURN;
  347.     END;
  348.  
  349.   call closeport('MetaScanRexxing');
  350.   EXIT(RetCode);
  351.  
  352.  
  353.